/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CloudPanel.java
 *
 * Created on Mar 27, 2011, 1:51:19 PM
 */

package gui;


import handler.*;

import java.util.ArrayList;



/**
 *
 * @author Catherine St. Peter
 */
public class CloudOpenPanel extends javax.swing.JFrame {
    private handler.DBHandler db;
    
    public Notebook nb = null;
    
    
    /** Creates new form CloudPanel */
    public CloudOpenPanel() {
        initComponents();

    }
    public CloudOpenPanel(int userid, Notebook nb) {
        id = userid;
        initComponents();
        this.nb = nb;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        CloudFileList = new javax.swing.JList();
        CloudOKButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        CloudFileList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = getFiles();
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });

        jScrollPane1.setViewportView(CloudFileList);

        CloudOKButton.setText("Open");
        CloudOKButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CloudOKButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(146, Short.MAX_VALUE)
                .addComponent(CloudOKButton)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(CloudOKButton)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private String[] getFiles() {
        DBHandler dbh = new DBHandler();
        ArrayList<NotebookFile> al = dbh.getAllNotebookFilesFromUser( id);
        String[] s = new String[al.size()];
        
        for(int i = 0; i < al.size(); i++) {
            s[i] = al.get(i).getNotebookFileName();            
        }        
        return s;
    }

//gets users and passes!
    /*
    private String[] getFiles() {
        DBHandler dbh = new DBHandler();
        ArrayList<User> al = dbh.getAllUsers();
        String[] s = new String[al.size()];

        for(int i = 0; i < al.size(); i++) {
            s[i] = (al.get(i).toString());
        }        
        return s;
    }
    */

   /* private String[] getFiles() {
        DBHandler dbh = new DBHandler();
      
        String[] s = new String[1];
        s[0]=dbh.getNotebookFilePermissions(10, 40).toString();
       
        return s;
    }*/
 

    private void CloudOKButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CloudOKButtonActionPerformed
        // TODO add your handling code here:
        // Open file from the cloud here
        
        System.out.println("Open");
        this.nb.fileToOpen = "eeeeeeeeeeee";
        
    }//GEN-LAST:event_CloudOKButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CloudOpenPanel().setVisible(true);
            }
        });
    }
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList CloudFileList;
    private javax.swing.JButton CloudOKButton;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
   private int id;
}
